This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing as t | |
class D: | |
def __set__(self, obj: t.Any, val: int, /) -> None: ... | |
class A: | |
desc = D() | |
desc_final: t.Final = D() | |
a: A = A() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing as t | |
class A: | |
@property | |
@t.final | |
def prop(self) -> int: | |
return 0 | |
@prop.setter | |
@t.final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing as t | |
class A: | |
@property | |
@t.final | |
def prop(self) -> int: | |
return 0 | |
@prop.setter | |
@t.final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing as t | |
class D: | |
def __set__(self, obj: t.Any, val: int, /) -> None: ... | |
class A: | |
desc: t.Final[D] = D() | |
@property | |
@t.final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
@dataclass | |
class A: | |
foo: int | |
@dataclass | |
class B: | |
bar: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bar: | |
pass | |
def foo() -> "Bar | None": | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Union | |
def foo(x: Union[int, float, str]): print(str(x)) | |
x: Union[int, Union[float, str]] = 7 | |
y: Union[int, Union[float, str]] = 3.0 | |
z: Union[int, Union[float, str]] = "hi" | |
foo(x) | |
foo(y) | |
foo(z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import assert_type, Any, Optional, TypeVar, overload | |
T = TypeVar("T") | |
@overload | |
def get(key: str) -> Optional[Any]: ... | |
@overload | |
def get(key: str, default: Any | T) -> Any | T: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Iterable | |
from enum import StrEnum | |
def takes_enum(e: StrEnum) -> StrEnum: | |
return e | |
def takes_enum_type(type_: type[StrEnum]) -> StrEnum: | |
return next(iter(type_)) # error: Incompatible return value type (got "str", expected "StrEnum") [return-value] | |
def takes_enum_type_with_trick(type_: type[StrEnum]) -> StrEnum: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Iterable | |
from enum import StrEnum | |
def takes_enum(e: StrEnum) -> StrEnum: | |
return e | |
def takes_enum_type(type_: type[StrEnum]) -> StrEnum: | |
return next(iter(type_)) | |
def takes_enum_type_with_trick(type_: type[StrEnum]) -> StrEnum: |
NewerOlder